package org.dailymoon.classifieds;

import javax.jws.WebMethod;

public class ClassifiedService {
	// @WebMethod(exclude = true)
	public static int createNewAd(String content, String endDate) {

		ClassifiedAd newAd = new ClassifiedAd();
		newAd.setEndDate(endDate);
		newAd.setContent(content);
		newAd.save();

		return 1;

	}

//	@WebMethod(exclude = true)
	public static boolean editExistingAd(ClassifiedAd adToEdit) {

		// Do stuff with the ad here
		return true;

	}

//	@WebMethod(exclude = true)
	public static ClassifiedList getExistingAds() {

		ClassifiedAd[] listOfAds = { new ClassifiedAd(), new ClassifiedAd(),
				new ClassifiedAd() };
		ClassifiedList listToReturn = new ClassifiedList(listOfAds);
		return listToReturn;
	}

	// @WebMethod(exclude = true)
	public static void finalizeIssue(String dateToFinalize) {
		// Don't return anything.
		System.out.println(dateToFinalize + " finalized.");
	}

	@WebMethod(exclude = true)
	public static void main(String args[]) {

		ClassifiedService.createNewAd(
				"Eclipse experts needed.  Contact Nick for details.",
				"4/21/2006");

		ClassifiedAd adToEdit = new ClassifiedAd();
		adToEdit.setId(1);
		adToEdit.setStartDate("4/8/2006");
		adToEdit.setEndDate("4/30/2006");
		adToEdit.setContent("Geronimo experts needed.  Contact Nick for details.");

		ClassifiedService.editExistingAd(adToEdit);

		ClassifiedList adList = ClassifiedService.getExistingAds();
		System.out.println(adList.toString());

	}

}